<?php

namespace WoXuanWang\Video\Models;

use Eloquent as Model;

/**
 * Class Source
 * @package WoXuanWang\Video\Models
 * @version April 12, 2017, 4:53 pm CST
 */
class Source extends Model
{
    public $table = 'video_sources';

    public $fillable = [
        'resolution',
        'type',
        'url',
        'parameters',
        'video_id',
        'created_by'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'resolution' => 'string',
        'type'       => 'string',
        'url'        => 'string',
        'parameters' => 'string',
        'video_id'   => 'integer',
        'created_by' => 'integer'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'resolution' => 'required'
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     **/
    public function video()
    {
        return $this->belongsTo(\WoXuanWang\Video\Models\Video::class, 'video_id', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function user()
    {
        return $this->hasOne(\WoXuanWang\User\Models\User::class, 'created_by', 'id');
    }
}
